import config from '@/config'
import store from '@/store'

const level = [
  {
    min: 0,
    max: 8,
    level: 0,
    color: '#2B0FF6',
    pointMultiple: 4
  },
  {
    min: 8,
    max: 15,
    level: 1,
    color: '#CC3737',
    pointMultiple: 4
  }
]

function symbolPointSize(val) {
  let r = ''
  for (let i = 0; i < level.length; i++) {
    const { max } = level[i]
    if (val[2] === max) {
      r = i + 1
      break
    }
  }

  return r * 4
}

export default {
  backgroundColor: 'transparent',
  tooltip: {
    trigger: 'item',
    formatter: function(val) {
      return '<div><h5>表具ID</h5>' + val.name + '</div>'
    }
  },
  bmap: {
    center: store.getters.mapCenter,
    zoom: 13,
    roam: true,
    enableDrawingTool: true,
    mapStyle: {
      styleJson: config.mapStyleJson
    }
  },
  series: [
    {
      name: '表具ID',
      type: 'scatter',
      coordinateSystem: 'bmap',
      animation: false,
      symbolSize: function(val) {
        return symbolPointSize(val)
      },
      label: {
        formatter: '{b}',
        position: 'right',
        show: false
      },
      emphasis: {
        label: {
          show: false
        }
      },
      itemStyle: {
        color: function(val = {}) {
          let currentColor = ''
          for (let i = 0; i < level.length; i++) {
            const { max, color } = level[i]
            if (val.value[2] === max) {
              currentColor = color
              break
            }
          }
          return currentColor
        }
      }
    },
    {
      name: '异常点',
      pointSize: 6,
      blurSize: 6,
      type: 'effectScatter',
      coordinateSystem: 'bmap',
      animation: false,
      symbolSize: function(val) {
        return symbolPointSize(val)
      },
      showEffectOn: 'render',
      rippleEffect: {
        brushType: 'stroke'
      },
      hoverAnimation: true,
      label: {
        formatter: '{b}',
        position: 'right',
        show: false
      },
      itemStyle: {
        color: function() {
          const { color } = level[level.length - 1]
          return color
        },
        shadowBlur: 10,
        shadowColor: '#333'
      },
      zlevel: 1
    }
  ]
}
